package com.shenmazong.serveredustudent.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.serveredustudent.mapper.TbClazzMapper;
import com.shenmazong.serveredustudent.pojo.TbArrangement;
import com.shenmazong.serveredustudent.pojo.TbClazz;
import com.shenmazong.serveredustudent.service.TbArrangementService;
import com.shenmazong.serveredustudent.mapper.TbArrangementMapper;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.ListParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class TbArrangementServiceImpl extends ServiceImpl<TbArrangementMapper, TbArrangement>
        implements TbArrangementService {

    @Autowired
    private TbArrangementMapper arrangementMapper;

    @Autowired
    private TbClazzMapper clazzMapper;

    @Override
    public ResultResponse getAllArrangementByClazzId(TbClazz clazz) {

        if (clazz == null) {
            return ResultResponse.FAILED(-1, "参数异常");
        }

        LambdaQueryWrapper<TbClazz> last = new QueryWrapper<TbClazz>().lambda().eq(TbClazz::getClazzId, clazz.getClazzId()).last("limit 1");

        TbClazz tbClazz = clazzMapper.selectOne(last);

        Byte clazzType = tbClazz.getClazzType();

        LambdaQueryWrapper<TbArrangement> eq = new QueryWrapper<TbArrangement>().lambda().eq(TbArrangement::getClazzType, clazzType);

        List<TbArrangement> tbArrangements = arrangementMapper.selectList(eq);

        return ResultResponse.SUCCESS(tbArrangements);
    }
}




